<!--
<template>
  <div>
    <div class="filingBox">
      <div class="rightContent">
        <div class="fixed-width">
          <transition name="fade" mode="out-in">
            <router-view></router-view>
          </transition>
        </div>
      </div>
    </div>
  </div>
</template>
-->
<template>
  <el-container class="layout-base" direction="vertical">
    <layout-header :title="title" hide-ad></layout-header>
    <el-container>
      <el-aside width="180px">
        <layout-menu :menu="showMenu"></layout-menu>
      </el-aside>
      <el-main>
        <div class="main">
          <router-view></router-view>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
// import HeaderBar from '../public/Header.vue'
// import NavBar from '../public/Nav.vue'
import LayoutHeader from '@/layouts/LayoutHeader'
import LayoutMenu from '@/layouts/LayoutMenu'

export default {
  name: 'OSS',
  components: {
    LayoutHeader,
    LayoutMenu,
  },
  created () {
    window.$adminInfo = this.getAdminInfo()
    this.formatRole()
  },
  data () {
    return {
      // 所有人都有的
      baseMenu: [
        {
          name: '首页',
          typeClass: 'el-icon-s-home',
          path: 'index',
        },
        {
          name: '报备审核',
          typeClass: 'el-icon-s-data',
          path: 'OSSFilings1',
          children: [
            {
              name: '报备审核',
              typeClass: 'el-icon-s-data',
              path: 'OSSFilings',
            },
            {
              name: '竞价报备',
              typeClass: 'el-icon-s-data',
              path: 'BidFilings',
            },
            {
              name: '商品上架',
              path: 'goods',
              // disabled: true,
            },
          ],
        },
        {
          name: '厂直订单',
          typeClass: 'el-icon-s-order',
          path: 'FactoryDirectOrder',
        },
        {
          name: '项目信息',
          typeClass: 'el-icon-s-grid',
          path: 'projectInfo',
        },
        {
          name: '用户管理',
          typeClass: 'el-icon-s-custom',
          path: 'UserManagement',
        },
      ],
      userRoleMenu: [
        {
          name: '用户管理',
          typeClass: 'el-icon-s-custom',
          path: 'UserManagement',
        },
      ],
      announcementRoleMenu: [
        {
          name: '公告管理',
          typeClass: 'el-icon-s-comment',
          path: 'Announcements',
        },
      ],
      settingRoleMenu: [
        {
          name: '项目设置',
          typeClass: 'el-icon-s-tools',
          path: 'Projects',
        },
      ],
      masterRoleMenu: [
        {
          name: '首页',
          typeClass: 'el-icon-s-home',
          path: 'index',
        },
        {
          name: '报备审核',
          typeClass: 'el-icon-s-data',
          path: 'OSSFilings1',
          children: [
            {
              name: '报备审核',
              typeClass: 'el-icon-s-data',
              path: 'OSSFilings',
            },
            {
              name: '竞价报备',
              typeClass: 'el-icon-s-data',
              path: 'BidFilings',
            },
            {
              name: '商品上架',
              path: 'goods',
              // disabled: true,
            },
          ],
        },
        {
          name: '厂直订单',
          typeClass: 'el-icon-s-order',
          path: 'FactoryDirectOrder',
        },
        {
          name: '项目信息',
          typeClass: 'el-icon-s-grid',
          path: 'projectInfo',
        },
        {
          name: '采购订单管理',
          typeClass: 'el-icon-s-order',
          path: 'PO',
        },
        {
          name: '用户管理',
          typeClass: 'el-icon-s-custom',
          path: 'UserManagement',
        },
        {
          name: '资质管理',
          typeClass: 'el-icon-s-management',  
          path: 'Qualification',
          children: [
            {
              name: '提报记录',
              typeClass: 'el-icon-key',
              path: 'Qualification_Verify_list',
            },
            {
              name: '证书信息库',
              typeClass: 'el-icon-key',
              path: 'Qualification_Category_list',
            },
          ],
        },
        {
          name: '公告管理',
          typeClass: 'el-icon-s-comment',
          path: 'Announcements',
        },
        {
          name: '项目设置',
          typeClass: 'el-icon-s-tools',
          path: 'Projects',
        },
        // {
        //   name: '项目管理',
        //   typeClass: 'el-icon-s-tools',
        //   path: 'Projects',
        //   children: [
        //     {
        //       name: '权限组',
        //       typeClass: 'el-icon-key',
        //       path: 'roleGroup',
        //     },
        //   ],
        // },

        {
          name: '账户权限',
          typeClass: 'el-icon-lock',
          path: 'role',
        },

      ],
      certificateRoleMenu: [
        {
          name: '资质管理',
          typeClass: 'el-icon-s-management',
          path: 'Qualification',
          children: [
            {
              name: '提报记录',
              typeClass: 'el-icon-key',
              path: 'Qualification_Verify_list',
            },
            {
              name: '证书信息库',
              typeClass: 'el-icon-key',
              path: 'Qualification_Category_list',
            },
          ],
        },
      ],
      roleGroupMenu: [
        {
          name: '权限组222',
          typeClass: 'el-icon-document-add',
          path: 'roleGroup',
        },
      ],
      PORoleMenu: [
        {
          name: '采购订单管理',
          typeClass: 'el-icon-s-order',
          path: 'PO',
        },
      ],
      menu: [],
      path: '',
      title: '“G采通”系统管理后台',
      index: 'OSSIndex',
    }
  },
  computed: {
    showMenu () {
      return this.formatMenu(this.menu)
    },
  },
  methods: {
    formatMenu (menu) {
      if (!menu) return []
      return menu.map(item => {
        const children = this.formatMenu(item.children)
        return {
          title: item.name,
          icon: item.typeClass,
          url: `/admin/${item.path}`,
          disabled: item.disabled === true,
          children,
        }
      })
    },
    formatRole () {
      // 超级管理员
      if (window.$adminInfo.type == -1) {
        this.menu = JSON.parse(JSON.stringify(this.masterRoleMenu))
      } else {
        // 一般管理员
        let menu = []
        menu = menu.concat(this.copyObject(this.baseMenu))
        if (window.$adminInfo.isUserRole) {
          menu = menu.concat(this.copyObject(this.userRoleMenu))
        }
        if (window.$adminInfo.isAnnouncementRole) {
          menu = menu.concat(this.copyObject(this.announcementRoleMenu))
        }
        if (window.$adminInfo.isSettingRole) {
          menu = menu.concat(this.copyObject(this.settingRoleMenu))
        }
        if (window.$adminInfo.isCertificateRole) {
          menu = menu.concat(this.copyObject(this.certificateRoleMenu))
        }
        if (window.$adminInfo.isRoleGroup) {
          menu = menu.concat(this.copyObject(this.roleGroupMenu))
        }
        this.menu = this.copyObject(menu)
        console.log('window.$adminInfo', window.$adminInfo)
      }
      console.log('menu', this.menu)
    },
  },
}
</script>

<style lang="less" scoped>
.main {
  min-width: 1250px;
  margin: 0 auto;
}
</style>
